package com.atguigu.system.controller;

import com.atguigu.common.result.Result;
import com.atguigu.model.vo.index.SysLoginReqVo;
import com.atguigu.model.vo.index.SysLoginRespVo;
import com.atguigu.model.vo.index.SysUserInfoRespVo;
import com.atguigu.system.service.IndexServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * IndexController
 * </p>
 *
 * @author flyduck
 * @since 2023/10/25
 */
@Api(tags = "用户登录接口")
@RestController
@RequestMapping("/admin/system/index")
public class IndexController {

    @Autowired
    private IndexServiceImpl indexServiceImpl;

    //{"code":20000,"data":{"token":"admin-token"}}
    @ApiOperation("登录")
    @PostMapping("/login")
    public Result<SysLoginRespVo> login(@RequestBody SysLoginReqVo reqVo){
        SysLoginRespVo respVo = indexServiceImpl.login(reqVo);
        return Result.ok(respVo);
    }

    //{
    //    "code": 20000,
    //    "data": {
    //        "roles": [
    //            "admin"
    //        ],
    //        "introduction": "I am a super administrator",
    //        "avatar": "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    //        "name": "Super Admin"
    //    }
    //}
    @ApiOperation("查询用户信息")
    @GetMapping("/info")
    public Result<SysUserInfoRespVo> info(@RequestHeader("token") String token){
        SysUserInfoRespVo respVo = indexServiceImpl.getUserInfo(token);
        return Result.ok(respVo);
    }
}
